(function (vc) {
    vc.extends({
        data: {
            adminRepairDetailInfo: {
                repairId: '',
                repairType: '',
                repairTypeName: '',
                repairName: '',
                tel: '',
                roomId: '',
                roomName: '',
                repairObjName: '',
                appointmentTime: '',
                context: '',
                stateName: '',
                userId: '',
                userName: '',
                repairUsers: [],
                photos: [],
                repairPhotos: [],
                beforePhotos: [],
                afterPhotos: [],
                visitType: '',
                visitContext: '',
                maintenanceType: '',
                repairMaterials: '',
                repairFee: '',
                resourceStoreInfo: [],
                appraiseScore: 0,
                doorSpeedScore: 0,
                repairmanServiceScore: 0,
                average: 0.0
            }
        },
        _initMethod: function () {
            let repairId = vc.getParam('repairId');
            if (!vc.notNull(repairId)) {
                vc.toast('非法操作');
                vc.jumpToPage('/#/pages/property/repairPoolManage');
                return;
            }
            $that.adminRepairDetailInfo.repairId = repairId;
            $that._listRepairPools()
        },
        _initEvent: function () {
            vc.on('adminRepairDetail','notifyRepairUser',function(){
                $that._loadRepairUser();
            })
        },
        methods: {
            _listRepairPools: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        repairId: $that.adminRepairDetailInfo.repairId
                    }
                };
                //发送get请求
                vc.http.apiGet('/ownerRepair.listAdminOwnerRepairs',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        let _repairs = _json.data;
                        if (_repairs.length < 1) {
                            vc.toast("数据异常");
                            vc.jumpToPage('/#/pages/property/repairPoolManage');
                            return;
                        }
                        vc.copyObject(_repairs[0], $that.adminRepairDetailInfo);
 
                        // 查询物品信息
                        let _maintenanceType = $that.adminRepairDetailInfo.maintenanceType;
                        if (_maintenanceType == '1001' || _maintenanceType == '1003') {
                            $that._loadResourceStoreList();
                        }
                        //查询处理轨迹
                        $that._loadRepairUser();
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadResourceStoreList: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        repairId: $that.adminRepairDetailInfo.repairId
                    }
                };
                //发送get请求
                vc.http.apiGet('/resourceStore.listAdminStoreUseRecords',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        let _resource = _json.data;
                        $that.adminRepairDetailInfo.resourceStoreInfo = _resource;
                        $that.adminRepairDetailInfo.resourceStoreInfo.forEach((item) => {
                            if (item.resId == '666666') {
                                item.rstName = item.specName = '自定义';
                            }
                        })
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _loadRepairUser: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 100,
                        repairId: $that.adminRepairDetailInfo.repairId
                    }
                };
                //发送get请求
                vc.http.apiGet('/ownerRepair.listAdminRepairStaffs',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        let _repairs = _json.data;
                        $that.adminRepairDetailInfo.repairUsers = _repairs;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _goBack: function () {
                vc.goBack()
            },
            openFile: function (_photo) {
                vc.emit('viewImage', 'showImage', {
                    url: _photo.url
                });
            },
        }
    });
})(window.vc);